# Makefile for NEGFC program
# Written by Cristian G. Sanchez UNC Cordoba
# August 2007
# Change flags for compiler if needed
# Tested for the g95 compiler (www.g95.org)

# Compiler and flags

#.SILENT:

#F90      = pgf95  
F90      = ifort  
# Make sure your compiler reads freeform somehow, otherwise lines WILL BE TRUNCATED!
## Debug
F90FLAGS += -O1 -check all -traceback
## More Debug
F90FLAGS += -g # -debug all #-warn all
F90FLAGS += -diag-dump
## Profiling
#F90FLAGS += -p
 F90FLAGS =  -O3 
 F90FLAGS = -fast 
# These are use only for the FDF, it's wise to use no optimization there "-O0"
#F77      = pgf95 
F77      = ifort 
F77FLAGS = -O0
#LINKFLAGS =  -static 
#LIBS = -llapack -lblas 
#LIBS = -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lguide -lpthread 
LIBS = -openmp  -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread


# how to produce objects from source files

%.o:%.f90
	$(F90) $(F90FLAGS) -c $<

%.o:%.f95
	$(F90) $(F90FLAGS) -c $<

%.o:%.f
	$(F77) $(F77FLAGS) -c $<

# General vars

TARGET = ../bin/principal

all: $(TARGET)

PROGRAM = principal.o

MODULES = constants.o control.o gcontacts.o hamiltonian.o matrixmod.o gdevice.o outcomes.o integration.o gaussquad.o algama.o

OBJS = $(PROGRAM) $(MODULES)

FDF = libfdf.a

# dependencies

gdevice.o : constants.o control.o matrixmod.o hamiltonian.o
principal.o :  constants.o control.o outcomes.o gdevice.o gcontacts.o hamiltonian.o matrixmod.o integration.o
constants.o : 
control.o : constants.o
gcontacts.o : constants.o control.o
hamiltonian.o : constants.o control.o matrixmod.o
matrixmod.o : control.o constants.o
outcomes.o : gdevice.o gcontacts.o matrixmod.o constants.o control.o integration.o hamiltonian.o 
integration.o : control.o matrixmod.o gaussquad.o gdevice.o
gaussquad.o : algama.f
algama.o :

$(MODULES) : $(FDF)
$(PROGRAM) : $(MODULES) $(FDF)

# rules

$(FDF):
	(cd fdf; $(MAKE) "F90=$(F90)" "F90FLAGS=$(F90FLAGSFDF)" "F77=$(F77)" "F77FLAGS=$(F77FLAGSFDF)" "ARFLAGS=$(ARFLAGS)" module)

$(TARGET):	$(MODULES) $(PROGRAM) $(FDF)
	$(F90) -o  $(TARGET) $(LINKFLAGS) $(OBJS) $(FDF) $(LIBS) $(LIBSP)  

clean:
	rm -f *.o *.mod programa  libfdf.a fdf.Standard work.pcl
	rm -f corriente.txt DOS_contacts.dat DOS_device.dat echo.out I_vs_V.dat 
	rm -f landauer.out transmision_function.dat
	rm -f *.txt
#	rm -f *.dat
	rm -f *.ps
	rm -f *.out
	rm -f fort.*
	rm -f principal
	rm -f *.agr
#	rm -f *.inp
	rm -f *.pdf
	(cd fdf; make clean)
	
